home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / clients / xclock / xclock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-12  |  4.9 KB  |  148 lines

  1. /* $XConsortium: xclock.c,v 1.32 91/04/19 13:46:20 converse Exp $ */
  2.  
  3. /*
  4.  * xclock --  Hacked from Tony Della Fera's much hacked clock program.
  5.  */
  6.  
  7. /*
  8.  * Copyright 1989 Massachusetts Institute of Technology
  9.  *
  10.  * Permission to use, copy, modify, distribute, and sell this software and its
  11.  * documentation for any purpose is hereby granted without fee, provided that
  12.  * the above copyright notice appear in all copies and that both that
  13.  * copyright notice and this permission notice appear in supporting
  14.  * documentation, and that the name of M.I.T. not be used in advertising or
  15.  * publicity pertaining to distribution of the software without specific,
  16.  * written prior permission.  M.I.T. makes no representations about the
  17.  * suitability of this software for any purpose.  It is provided "as is"
  18.  * without express or implied warranty.
  19.  *
  20.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  22.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  25.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  */
  27.  
  28. #include <X11/Xatom.h>
  29. #ifdef MSDOS
  30. #include "X11/Intrinsc.h"      /* QDK 05/12/1994 10:47am. */
  31. #else
  32. #include "X11/Intrinsic.h"
  33. #endif
  34. #include <X11/StringDefs.h>
  35. #include <X11/Shell.h>
  36. #include <X11/Xaw/Clock.h>
  37. #include <X11/Xaw/Cardinals.h>
  38. #include "clock.bit"
  39. #include "clmask.bit"
  40.  
  41. #ifndef MSDOS
  42. extern void exit();
  43. #endif
  44. static void quit();
  45.  
  46. /* Command line options table.  Only resources are entered here...there is a
  47.    pass over the remaining options after XtParseCommand is let loose. */
  48.  
  49. static XrmOptionDescRec options[] = {
  50. {"-chime",    "*clock.chime",        XrmoptionNoArg,        "TRUE"},
  51. {"-hd",        "*clock.hands",        XrmoptionSepArg,    NULL},
  52. {"-hands",    "*clock.hands",        XrmoptionSepArg,    NULL},
  53. {"-hl",        "*clock.highlight",    XrmoptionSepArg,    NULL},
  54. {"-highlight",    "*clock.highlight",    XrmoptionSepArg,    NULL},
  55. {"-update",    "*clock.update",    XrmoptionSepArg,    NULL},
  56. {"-padding",    "*clock.padding",    XrmoptionSepArg,    NULL},
  57. {"-d",        "*clock.analog",    XrmoptionNoArg,        "FALSE"},
  58. {"-digital",    "*clock.analog",    XrmoptionNoArg,        "FALSE"},
  59. {"-analog",    "*clock.analog",    XrmoptionNoArg,        "TRUE"},
  60. };
  61.  
  62.  
  63. static XtActionsRec xclock_actions[] = {
  64.     { "quit",    quit },
  65. };
  66.  
  67. static Atom wm_delete_window;
  68.  
  69. /*
  70.  * Report the syntax for calling xclock.
  71.  */
  72. Syntax(call)
  73.     char *call;
  74. {
  75.     (void) printf ("Usage: %s [-analog] [-bw <pixels>] [-digital]\n", call);
  76.     (void) printf ("       [-fg <color>] [-bg <color>] [-hd <color>]\n");
  77.     (void) printf ("       [-hl <color>] [-bd <color>]\n");
  78.     (void) printf ("       [-fn <font_name>] [-help] [-padding <pixels>]\n");
  79.     (void) printf ("       [-rv] [-update <seconds>] [-display displayname]\n");
  80.     (void) printf ("       [-geometry geom]\n\n");
  81.     exit(1);
  82. }
  83.  
  84. void main(argc, argv)
  85.     int argc;
  86.     char **argv;
  87. {
  88.     Widget toplevel;
  89.     Arg arg;
  90.     Pixmap icon_pixmap = None;
  91.     XtAppContext app_con;
  92.  
  93.     toplevel = XtAppInitialize (&app_con, "XClock", options, XtNumber(options),
  94.                 &argc, argv, NULL, NULL, ZERO);
  95.     if (argc != 1) Syntax(argv[0]);
  96.  
  97.     XtAppAddActions (app_con, xclock_actions, XtNumber(xclock_actions));
  98.  
  99.     /*
  100.      * This is a hack so that f.delete will do something useful in this
  101.      * single-window application.
  102.      */
  103.     XtOverrideTranslations(toplevel, 
  104.             XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  105.  
  106.     XtSetArg(arg, XtNiconPixmap, &icon_pixmap);
  107.     XtGetValues(toplevel, &arg, ONE);
  108.     if (icon_pixmap == None) {
  109.     arg.value = (XtArgVal)XCreateBitmapFromData(XtDisplay(toplevel),
  110.                        XtScreen(toplevel)->root,
  111.                        (char *)clock_bits, clock_width, clock_height);
  112.     XtSetValues (toplevel, &arg, ONE);
  113.     }
  114.     XtSetArg(arg, XtNiconMask, &icon_pixmap);
  115.     XtGetValues(toplevel, &arg, ONE);
  116.     if (icon_pixmap == None) {
  117.     arg.value = (XtArgVal)XCreateBitmapFromData(XtDisplay(toplevel),
  118.                        XtScreen(toplevel)->root,
  119.                        (char *)clock_mask_bits, clock_mask_width, 
  120.                        clock_mask_height);
  121.     XtSetValues (toplevel, &arg, ONE);
  122.     }
  123.  
  124.     XtCreateManagedWidget ("clock", clockWidgetClass, toplevel, NULL, ZERO);
  125.     XtRealizeWidget (toplevel);
  126.     wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
  127.                     False);
  128.     (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
  129.                 &wm_delete_window, 1);
  130.     XtAppMainLoop (app_con);
  131. }
  132.  
  133.  
  134. static void quit (w, event, params, num_params)
  135.     Widget w;
  136.     XEvent *event;
  137.     String *params;
  138.     Cardinal *num_params;
  139. {
  140.     if (event->type == ClientMessage &&
  141.     event->xclient.data.l[0] != wm_delete_window) {
  142.     XBell (XtDisplay(w), 0);
  143.     return;
  144.     }
  145.     XCloseDisplay (XtDisplay(w));
  146.     exit (0);
  147. }
  148.